package com.webex.ta.hydra.gui.table;

import com.webex.ta.hydra.util.HydraUtils;

import javax.swing.*;
import javax.swing.border.Border;
import java.awt.*;

/**
 * Created by Cisco WebEx.
 * User: vegaz
 * Date: 2010-8-31
 * Time: 9:39:35
 */
public class DefaultCellBorder implements Border {
    private boolean isError;
    private Color borderColor;

    static final Icon ERR_BG;
    static final int BG_WIDTH;

    public DefaultCellBorder(Color borderColor) {
        this(false, borderColor);
    }

    public DefaultCellBorder(boolean isError, Color borderColor) {
        this.isError = isError;
        this.borderColor = borderColor;
    }

    static {
        ERR_BG = HydraUtils.getImage("errcheck_bg.gif");
        BG_WIDTH = ERR_BG.getIconWidth();
    }

    public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
        g.setColor(borderColor);
        g.drawRect(x,y,width-1,height-1);
        if (isError) {
            for (int i = 0 ; i < width / BG_WIDTH; i++) {
                ERR_BG.paintIcon(c, g, ERR_BG.getIconWidth()* i, y + height - ERR_BG.getIconHeight());
            }
        }
    }

    public Insets getBorderInsets(Component c) {
        return new Insets(1,1,1,1);
    }

    public boolean isBorderOpaque() {
        return false;
    }
}
